package fpzhan.plane.program.connect;

import fpzhan.plane.program.describe.IfsComment;
import fpzhan.plane.program.function.ConditionFunction;

import java.util.Collections;

public class ConditionMixCodeBlockConnect extends MixCodeBlockConnect {


    public ConditionMixCodeBlockConnect(CodeBlockContext context, ChainCodeBlockConnect source) {
        super(context, source);
        this.aloneCodeBlockCompose = new ConditionCodeBlockCompose();
    }


    public IfsComment<ConditionCodeBlockCompose,ChainCodeBlockConnect> ifs(ConditionFunction conditionFunction) {
        ChainCodeBlockConnect connect = new ChainCodeBlockConnect(getContext(),
                this);
        ((ConditionCodeBlockCompose) this.aloneCodeBlockCompose).getKeyConnect().put(conditionFunction, connect);
        return new IfsComment(( this.aloneCodeBlockCompose), connect);
    }

    public  IfsComment<ConditionCodeBlockCompose,ChainCodeBlockConnect>  defaults(){
        return ifs(param -> true);
    }


    public ChainCodeBlockConnect branchEnd() {
        ChainCodeBlockConnect connect = (ChainCodeBlockConnect) getSource();
        connect.addChainBlocks(Collections.singletonList(this.aloneCodeBlockCompose));
        return connect;
    }


}
